package labelsystem.Controller;/**
 * @projectName careOlder
 * @Description TODO
 * @author MCG
 * @time 2023/3/30 13:43
 */

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import labelsystem.Mapper.monitorMapper;
import labelsystem.Pojo.*;
import labelsystem.Service.ouserService;
import labelsystem.utils.monitorHandle;
import labelsystem.utils.returnMSG;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.time.Duration;
import java.time.LocalDateTime;
import java.util.List;

/**
 *description: TODO
 *@author MCG
 *@date 2023/3/30 13:43
 *@Version 1.0
 */
@Api("老人处理模块")
@RestController
@CrossOrigin
public class ouserHandler {
    @Resource
    ouserService ouserService;

    @PostMapping("/loginInO")
    @ApiOperation("老人登陆:phone")
    public returnMSG login(@RequestParam("phone") String phone){
        OlderUser olderUser=ouserService.loginIn(phone);
        returnMSG returnMSG= labelsystem.utils.returnMSG.success();
        returnMSG.add("olduser",olderUser);
        return returnMSG;
    }
    @GetMapping("/queryOrdersO")
    @ApiOperation("查询订单:oid")
    public returnMSG queryOrders(@RequestParam("oid") String oid){
        List<Order> orders=ouserService.queryOrders(Long.parseLong(oid));
        returnMSG returnMSG= labelsystem.utils.returnMSG.success();
        returnMSG.add("orders",orders);
        return returnMSG;

    }
    @GetMapping("/clickO")
    @ApiOperation("签到:oid")
    public returnMSG clickO(@RequestParam("oid") String oid){
        Monitor monitor=ouserService.queryMonitorById(oid);
        LocalDateTime localDateTime=LocalDateTime.now();
        LocalDateTime startTime=monitor.getCreateTime();
        Duration duration=Duration.between(startTime,localDateTime);
        Long between=duration.toDays();
        if(between>monitor.getIsUsed().length()){
            returnMSG returnMSG= labelsystem.utils.returnMSG.fail();
            returnMSG.setMsg("请勿在监测时间外签到");
            return returnMSG;
        }
        monitorHandle monitorHandle=ouserService.click(Long.parseLong(oid),monitor,between);
        returnMSG returnMSG= labelsystem.utils.returnMSG.success();
        returnMSG.add("monitor",monitorHandle);
        return returnMSG;
    }
    @GetMapping("/queryCheckO")
    @ApiOperation("查询体检单:oid")
    public returnMSG queryCheck(@RequestParam("oid") String oid){
        List<Check> checks=ouserService.queryCheck(Long.parseLong(oid));
        returnMSG returnMSG= labelsystem.utils.returnMSG.success();
        returnMSG.add("checks",checks);
        return returnMSG;
    }
    @GetMapping("/queryInfoO")
    @ApiOperation("查询个人信息:oid")
    public returnMSG queryInfoO(@RequestParam("oid") String oid){
        OlderUser olderUser=ouserService.queryInfo(Long.parseLong(oid));
        returnMSG returnMSG= labelsystem.utils.returnMSG.success();
        returnMSG.add("olderuser",olderUser);
        return returnMSG;
    }
    @PostMapping("/queryMonitorO")
    @ApiOperation("查询检测:oid")
    public returnMSG queryMonitorO(@RequestParam("oid") String oid){
        monitorHandle monitorHandle=ouserService.queryMonitor(Long.parseLong(oid));
        returnMSG returnMSG= labelsystem.utils.returnMSG.success();
        returnMSG.add("monitor",monitorHandle);
        return returnMSG;
    }
    @GetMapping("/queryDoctorsO")
    @ApiOperation("查询医生")
    public returnMSG queryDoctors(){
        List<Doctor> doctors=ouserService.queryDoctors();
        returnMSG returnMSG= labelsystem.utils.returnMSG.success();
        returnMSG.add("doctors",doctors);
        return returnMSG;
    }
    @GetMapping("/queryDoctorsByIdO")
    @ApiOperation("查询医生:did")
    public returnMSG queryDoctorById(@RequestParam("did") String did){
        Doctor doctor=ouserService.queryDoctorById(Long.parseLong(did));
        returnMSG returnMSG= labelsystem.utils.returnMSG.success();
        returnMSG.add("doctor",doctor);
        return returnMSG;
    }

    @GetMapping("/queryDoctorBySpecifyO")
    @ApiOperation("specify查询医生:specify")
    public returnMSG queryDoctorBySpecify(@RequestParam("specify") String specify){
        List<Doctor> doctors=ouserService.queryDoctorsBySpecify(specify);
        returnMSG returnMSG= labelsystem.utils.returnMSG.success();
        returnMSG.add("doctors",doctors);
        return returnMSG;
    }
    @GetMapping("/queryVolunteerO")
    @ApiOperation("查询护工")
    public returnMSG queryVolunteer(){
        List<Volunteer> volunteers=ouserService.queryVolunteers();
        returnMSG returnMSG= labelsystem.utils.returnMSG.success();
        returnMSG.add("volunteers",volunteers);
        return returnMSG;
    }
    @GetMapping("/queryVolunteerByIdO")
    @ApiOperation("id查询护工:id")
    public returnMSG queryVolunteer(@RequestParam("vid") String vid){
        Volunteer volunteer=ouserService.queryVolunteerById(Long.parseLong(vid));
        returnMSG returnMSG= labelsystem.utils.returnMSG.success();
        returnMSG.add("volunteer",volunteer);
        return  returnMSG;
    }

    @PostMapping("/ratingDoctorO")
    @ApiOperation("医生评分：oid，rating,did")
    public returnMSG ratingDoctor(@RequestParam("oid") String oid,@RequestParam("rating") String rating,@RequestParam("did") String did){
       boolean flag=ouserService.rateDoctor(Long.parseLong(oid),Float.parseFloat(rating),Long.parseLong(did));
       if(flag){
           return returnMSG.success();
       }else{
           return returnMSG.fail();
       }
    }

    @PostMapping("/ratingVolunteerO")
    @ApiOperation("护工评分:oid,rating,vid")
    public returnMSG ratingVolunteer(@RequestParam("oid")String oid,@RequestParam("rating") String rating,@RequestParam("vid")String vid){
        boolean flag=ouserService.rateVolunteer(Long.parseLong(oid),Float.parseFloat(rating),Long.parseLong(oid));
        if(flag){
            return returnMSG.success();
        }else {
            return returnMSG.fail();
        }
    }

    @PostMapping("/createVOrderO")
    @ApiOperation("生成护工订单:oid,oname,vid,vname")
    public returnMSG createOrderV(@RequestParam("oid") String oid,@RequestParam("oname") String oname,@RequestParam("vid") String vid,@RequestParam("vname") String vname){
        boolean flag=ouserService.createDOrder(Long.parseLong(oid),oname,Long.parseLong(vid),vname,Float.parseFloat("45.0"));
        if(flag){
            return returnMSG.success();
        }else{
            return returnMSG.fail();
        }
    }

    @PostMapping("/createDOrderO")
    @ApiOperation("生成医生订单:oid,oname,did,dname")
    public returnMSG createOrderD(@RequestParam("oid") String oid,@RequestParam("oname") String oname,@RequestParam("did") String did,@RequestParam("dname") String dname){
        boolean flag=ouserService.createDOrder(Long.parseLong(oid),oname,Long.parseLong(did),dname,Float.parseFloat("60.0"));
        if(flag){
            return returnMSG.success();
        }else{
            return returnMSG.fail();
        }
    }

    @PostMapping("/updateInfoO")
    @ApiOperation("更改个人信息:oid,address,status")
    public returnMSG updateInfoO(@RequestParam("oid") String oid,@RequestParam("address") String address,@RequestParam("status") String status){
        OlderUser olderUser=ouserService.queryInfo(Long.parseLong(oid));
        if(!address.equals(olderUser.getAddress())) olderUser.setAddress(address);
        if(!status.equals(olderUser.getStatus())) olderUser.setStatus(status);
        ouserService.updateInfo(olderUser);
        returnMSG returnMSG= labelsystem.utils.returnMSG.success();
        returnMSG.add("olderuser",olderUser);
        return returnMSG;
    }


}
